Skip to content

Extend the prefer-array-some rule to also detect filter().length calls - #113

Merged
43081j merged 1 commit into
e18e:mainfrom
ashleylamont:ashleylamont/prefer-array-some-filter-length
May 10, 2026
Merged

43081j merged 1 commit into
e18e:mainfrom
ashleylamont:ashleylamont/prefer-array-some-filter-length

Conversation

@ashleylamont

@ashleylamont ashleylamont commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Extend prefer-array-some to cover array.filter(fn).length checks

Covers numeric comparisons (> 0, !== 0, >= 1 and negations), flipped operands, boolean context, and !/!! prefixes. Updates rule description and README to match.

Not flagged:

  • filter().length with no args — .some() with no args throws TypeError
  • Quantity comparisons (> 1, === 3 etc.) — not existence checks
  • Always-true/false patterns (>= 0, < 0) — logic bugs, out of scope
  • Loose equality (== 0, != 0) — strict only

Also refactors isFindCall into a shared isArrayMethodCall helper, which as a side effect extends existing find (and new filter) detection to also match on string property access (e.g. arr['find'](fn)).

@ashleylamont
ashleylamont marked this pull request as ready for review May 8, 2026 05:54
@43081j

43081j commented May 10, 2026

Copy link
Copy Markdown
Contributor

super nice work 🎉

looks good to me 👍

@43081j
43081j merged commit 515634d into e18e:main May 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants